package com.cdu.util;

import com.cdu.model.UserDetail;
import com.cdu.pojo.News;
import com.cdu.pojo.Task;
import com.cdu.pojo.User;

import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
import java.util.stream.Collectors;

/**
 * @program: easy-help-v2
 * @description: pojo转model工具类
 * @author: hanabi
 * @create: 2022-05-17 11:24
 **/

public class ConvertUtils {
    //将User转换为UserDetail
    public static UserDetail convertUserDetail(User user, List<Task> taskList, List<News> newsList) {
        UserDetail userDetail = new UserDetail();
        userDetail.setUsername(user.getUsername());
        userDetail.setId(user.getId());
        userDetail.setPassword(user.getPassword());
        userDetail.setBedroomAddr(user.getBedroomAddr());
        userDetail.setQq(user.getQq());
        userDetail.setRealName(user.getRealName());
        userDetail.setRemark(user.getRemark());
        userDetail.setReputation(user.getReputation());
        userDetail.setTel(user.getTel());
        userDetail.setCreator(user.getCreator());
        userDetail.setCreateTime(user.getCreateTime());
        userDetail.setModifier(user.getModifier());
        userDetail.setUpdateTime(user.getUpdateTime());
        List<Task> acceptedTasks = taskList.stream().filter(task -> task.getReceiveUserId().equals(user.getId())).collect(Collectors.toList());
        userDetail.setTaskList(taskList);
        userDetail.setAcceptedTaskList(acceptedTasks);
        userDetail.setNewsList(newsList);
        return userDetail;
    }

}
